﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:FIN_VOUCHERJOUHIS
	/// </summary>
	public partial class FIN_VOUCHERJOUHIS : BaseDAL<GSLMS.Entity.TB_FIN_VOUCHERJOUHIS>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public FIN_VOUCHERJOUHIS()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_FIN_VOUCHERJOUHIS model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_VOUID", model.VOUID),
								new OracleParameter("P_SUMMARY", model.SUMMARY),
								new OracleParameter("P_SUBNAME", model.SUBNAME),
								new OracleParameter("P_SUBID", model.SUBID),
								new OracleParameter("P_SUBCODE", model.SUBCODE),
								new OracleParameter("P_SUBNAMEALL", model.SUBNAMEALL),
								new OracleParameter("P_AMT", model.AMT),
								new OracleParameter("P_DIRECT", model.DIRECT)};
  
			for (int i = 0; i < 9; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_fin_voucherjouhis_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_FIN_VOUCHERJOUHIS model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_VOUID", model.VOUID),
								new OracleParameter("P_SUMMARY", model.SUMMARY),
								new OracleParameter("P_SUBNAME", model.SUBNAME),
								new OracleParameter("P_SUBID", model.SUBID),
								new OracleParameter("P_SUBCODE", model.SUBCODE),
								new OracleParameter("P_SUBNAMEALL", model.SUBNAMEALL),
								new OracleParameter("P_AMT", model.AMT),
								new OracleParameter("P_DIRECT", model.DIRECT)};
  
			for (int i = 0; i < 9; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_fin_voucherjouhis_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_fin_voucherjouhis_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_FIN_VOUCHERJOUHIS DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_FIN_VOUCHERJOUHIS model = new GSLMS.Entity.TB_FIN_VOUCHERJOUHIS();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["VOUID"]!=null && dr["VOUID"].ToString()!="")
				{
					model.VOUID=OracleHelper.ToLong(dr["VOUID"].ToString());
				}
				if(dr["SUMMARY"]!=null && dr["SUMMARY"].ToString()!="")
				{
					model.SUMMARY=dr["SUMMARY"].ToString();
				}
				if(dr["SUBNAME"]!=null && dr["SUBNAME"].ToString()!="")
				{
					model.SUBNAME=dr["SUBNAME"].ToString();
				}
				if(dr["SUBID"]!=null && dr["SUBID"].ToString()!="")
				{
					model.SUBID=OracleHelper.ToLong(dr["SUBID"].ToString());
				}
				if(dr["SUBCODE"]!=null && dr["SUBCODE"].ToString()!="")
				{
					model.SUBCODE=dr["SUBCODE"].ToString();
				}
				if(dr["SUBNAMEALL"]!=null && dr["SUBNAMEALL"].ToString()!="")
				{
					model.SUBNAMEALL=dr["SUBNAMEALL"].ToString();
				}
				if(dr["AMT"]!=null && dr["AMT"].ToString()!="")
				{
					model.AMT=OracleHelper.ToDecimal(dr["AMT"].ToString());
				}
				if(dr["DIRECT"]!=null && dr["DIRECT"].ToString()!="")
				{
                    model.DIRECT = OracleHelper.ToInt(dr["DIRECT"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_FIN_VOUCHERJOUHIS GetByID(long ID)
		{
			GSLMS.Entity.TB_FIN_VOUCHERJOUHIS sModel = new GSLMS.Entity.TB_FIN_VOUCHERJOUHIS();
			string sql = "";
			sql = "select * from TB_FIN_VOUCHERJOUHIS where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_FIN_VOUCHERJOUHIS> GetList(GSLMS.Entity.TB_FIN_VOUCHERJOUHIS searchParam)
		{
			var list=new List<GSLMS.Entity.TB_FIN_VOUCHERJOUHIS>();
			DataTable dt = null;
			string tblName = "TB_FIN_VOUCHERJOUHIS";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_FIN_VOUCHERJOUHIS model = new GSLMS.Entity.TB_FIN_VOUCHERJOUHIS();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

